﻿@model product

@{
    ViewBag.Title = "添加商品";
}
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>添加商品</legend>
</fieldset>

<form class="layui-form" method="post">
    @Html.HiddenFor(model=>model.id)
    <div class="layui-form-item">
        <label class="layui-form-label">商品名称</label>
        <div class="layui-input-block">
            @Html.TextBoxFor(model => model.product_name, new { @class = "layui-input", lay_verify = "required", placeholder = "请输入商品名称" })
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">库存</label>
        <div class="layui-input-block">
            @Html.TextBoxFor(model => model.product_num, new { @class = "layui-input", lay_verify = "required", placeholder = "请输入库存" })
            <input type="text" name="product_num" lay-verify="required" placeholder="请输入库存" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">保存</button>
        </div>
    </div>
</form>

@section scripts{
    <script>
        layui.use(['form', 'layedit'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit;

            //监听提交
            form.on('submit(demo1)', function (data) {
                $.post("@Url.Action("Add")", data.field, function (result) {
                    if (result.success) {
                        layer.msg(result.message, {icon: 1}, function () {
                            location.href = '@Url.Action("Index")';
                        });
                    } else {
                        layer.msg(result.message, { icon: 2 });
                    }
                });
                return false;
            });


        });
    </script>

}